//
//  MSTableViewController.m
//  VGirl
//
//  Created by danal on 13-5-8.
//  Copyright (c) 2013年 danal. All rights reserved.
//

#import "MSTableViewController.h"

@interface MSTableViewController ()

@end

@implementation MSTableViewController
@synthesize style = _style;
@synthesize tableView = _tableView;
@synthesize dataList = _dataList;
@synthesize heightList = _heightList;
@synthesize offset = _offset;

- (void)dealloc{
    _tableView.dataSource = nil;
    _tableView.delegate = nil;
    [_heightList release];  _heightList = nil;
    [_dataList release];    _dataList = nil;
    [super dealloc];
}

- (id)init{
    self = [super init];
    if (self) {
        _dataList = [[NSMutableArray alloc] init];
        _heightList = [[NSMutableArray alloc] init];
        _style = UITableViewStylePlain;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:_style];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [self.view addSubview:_tableView];
    [_tableView release];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setOffset:(CGPoint)offset{
    CGRect rect = self.tableView.frame;
    rect.origin = offset;
    rect.size.height -= offset.y;
    rect.size.width -= offset.x;
    self.tableView.frame = rect;
}

#pragma mark - Delegate methods

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [self heightForIndexPath:indexPath] > 0.f ? [self heightForIndexPath:indexPath] : 44.f;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.dataList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [self cellForIndexPath:indexPath];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - The following methods should be overrided

- (CGFloat)heightForIndexPath:(NSIndexPath *)indexPath{
    return 0.f;
}

- (UITableViewCell *)cellForIndexPath:(NSIndexPath *)indexPath{
    return nil;
}

@end
